<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .register-container {
            max-width: 400px;
            width: 100%;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            margin-bottom: 20px;
            color: #333;
        }
        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 16px;
        }
        input[type="button"] {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        input[type="button"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>

<div class="register-container">
    <h1>注册页面</h1>
    <input type="text" placeholder="用户名" v-model="user.username">
    <input type="password" placeholder="密码" v-model="user.password">
    <input type="text" placeholder="昵称" v-model="user.nickname">
    <input type="button" value="注册" @click="reg()">
</div>

<!-- 引入axios和vue的框架文件 -->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el: ".register-container",
        data: {
            user: {
                username: "",
                password: "",
                nickname: ""
            }
        },
        methods: {
            reg() {
                axios.post("/v1/users/reg", v.user)
                    .then(function (response) {
                        if (response.data === 1) {
                            alert("注册成功");
                            location.href = "/";
                        } else {
                            alert("用户名已存在");
                        }
                    });
            }
        }
    });
</script>

</body>
</html>
